<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/24/024
 * Time: 20:12
 */

namespace app\api\validate;

class MemberProfileValidate extends \think\Validate
{

    const SCENE_EDIT_IMAGE = 'edit_image'; //编辑头像
    const SCENE_EDIT_NICKNAME = 'edit_nick_name'; //编辑昵称
    const SCENE_EDIT_SEX = 'edit_sex'; //编辑性别
    const SCENE_EDIT_BIRTH = 'edit_birth'; //编辑性别
    const SCENE_EDIT_ADDRESS = 'edit_address'; //编辑性别


    protected $rule = [
        'type' => 'require|number|checkType',
        'nick_name'  =>  'require|max:32',
        'image'  =>  'require|max:250',
        'sex'  =>  'require|number',
        'pid'  =>  'require|number',
        'cid'  =>  'require|number',
        'birth'  =>  'require|max:30',
    ];


    protected $message  = [
        'type.require' => '类型必须',
        'type.number' => '类型为数字',
        'nick_name.require' => '昵称必须',
        'nick_name.max' => '昵称最长32个字符',
        'image.require' => '头像必须',
        'image.max' => '头像最长250个字符',
        'sex.require' => '性别必须',
        'sex.number' => '性别为数字',
        'pid.require' => '省级ID必须',
        'pid.number' => '省级ID为数字',
        'cid.require' => '市级ID必须',
        'cid.number' => '市级ID为数字',
        'birth.require' => '生日必须',
        'birth.max' => '生日最长30个字符',
    ];
    
    //场景
    protected $scene  = [
       self::SCENE_EDIT_IMAGE => ['type', 'image'],
       self::SCENE_EDIT_NICKNAME => ['type', 'nick_name'],
       self::SCENE_EDIT_SEX => ['type', 'sex'],
       self::SCENE_EDIT_BIRTH => ['type', 'birth'],
       self::SCENE_EDIT_ADDRESS => ['type', 'pid', 'cid'],
    ];

    
    //校验类型
    public function checkType($value) {
        $type = [1, 2, 3, 4, 5];
        return in_array($value, $type) ? true : '编辑类型错误';
    }

}